<?php

namespace App\Trip\Train\Seat;

use App\Trip\Train\Seat\Interfaces\SeatInfoInterface;
use Illuminate\Support\Str;

class SeatInfo implements SeatInfoInterface
{
    private string $name;
    private string $name_uy;
    private float  $price;
    private Seats  $seat;

    public function __construct(Seats $seatInfo, string $name, float $price)
    {
        $this->seat    = $seatInfo;
        $this->name    = $name;
        $trans_name    = Str::replace($seatInfo->getName(), '', $name);
        $this->name_uy = SeatName::trans($trans_name, 'uy');
        $this->price   = $price;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function __toString()
    {
        return json_encode($this->toArray(), JSON_UNESCAPED_UNICODE);
    }

    public function toArray(): array
    {
        return [
            "train_code" => $this->seat->getTrainCode(),
            "from_code"  => $this->seat->getFromStationCode(),
            "to_code"    => $this->seat->getToStationCode(),
            "seat_name"  => $this->seat->getName(),
            "name"       => $this->getName(),
            "name_uy"    => $this->getNameUy(),
            "price"      => $this->getPrice(),
        ];
    }

    public function getNameUy(): string
    {
        return $this->name_uy;
    }

    public function getPrice(): float
    {
        return $this->price;
    }
}